package com.modbus.tcp.controller;

import java.util.List;

import com.modbus.tcp.utils.ApiReturnObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.modbus.tcp.domain.Minecompany;
import com.modbus.tcp.service.IMinecompanyService;


/**
 * 煤矿公司 信息操作处理
 *
 * @author d
 * @date 2024-01-11
 */
@RestController
@RequestMapping("/minecompany")
public class MinecompanyController  {

    @Autowired
    private IMinecompanyService minecompanyService;

    /**
     * 查询煤矿公司列表
     */
    @GetMapping("/list")
    public ApiReturnObject list(Minecompany minecompany,Integer pageNum,Integer pageSize) {
        if(pageNum != null && pageSize !=null ){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<Minecompany> list = minecompanyService.selectMinecompanyList(minecompany);
        PageInfo pageInfo = new PageInfo<>(list);
        return new ApiReturnObject("200","查询成功",pageInfo);
    }


    /**
     * 新增保存煤矿公司
     */

    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody Minecompany minecompany) {
        minecompanyService.insertMinecompany(minecompany);
        return new ApiReturnObject("200","添加成功","");
    }


    /**
    * 详情煤矿公司
    */
    @GetMapping("/selectOne")
    public ApiReturnObject selectOne(Integer id){
        Minecompany result = minecompanyService.selectMinecompanyById(id);
        return new ApiReturnObject("200","查询成功",result);
    }

    /**
     * 修改保存煤矿公司
     */

    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody Minecompany minecompany) {
        minecompanyService.updateMinecompany(minecompany);
        return new ApiReturnObject("200","修改成功","");
    }

    /**
     * 删除煤矿公司
     */

    @PostMapping("/del")
    public ApiReturnObject remove(String ids) {
        minecompanyService.deleteMinecompanyByIds(ids);
        return new ApiReturnObject("200","删除成功","");
    }
}